package com.example.backend.mapper;

import com.example.backend.pojo.Foodorder;
import com.example.backend.pojo.Orderdetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {
    @Insert("insert into foodorder set orderid=#{orderid},userid=#{userid},restaurantid=#{restaurantid},price=#{price},createtime=now(),person=#{person},way=#{way},state=0")
    void addOrder(Foodorder foodorder);

    @Select("select count(orderid) from foodorder ")
    Integer count();

    @Insert("insert into orderdetail set orderid=#{orderid},foodid=#{foodid}, price=#{price}, number=#{number}")
    void adddetail(Orderdetail detail);

    @Select("select * from foodorder where userid=#{id} ")
    List<Foodorder> getuserorder(Integer id);
    @Select("select * from orderdetail where orderid=#{id} ")
    List<Orderdetail> getuserorderdetail(Integer id);
    @Update("update foodorder set complainid=#{complainid},state=1 where orderid=#{orderid}")
    void updatecomplain(@Param("complainid")Integer complainid, @Param("orderid")Integer orderid);
    @Update("update foodorder set reviewid=#{reviewid} where orderid=#{orderid}")
    void updatereview( @Param("reviewid")Integer reviewid, @Param("orderid")Integer orderid);
    @Select("select * from foodorder where userid=#{id} and state=#{state} ORDER BY createtime DESC ")
    List<Foodorder> getuserorderx(@Param("id")Integer id, @Param("state")Integer state);
    @Select("select * from foodorder where restaurantid=#{id} and state=#{state} ")
    List<Foodorder> getresorder(@Param("id")String id,  @Param("state")Integer state);

    @Update("update foodorder set state=#{state} where  orderid=#{orderid}")
    void updateorder(String orderid,Integer state);

    @Select("select  * from foodorder where orderid=#{orderid}")
    Foodorder findbyId(Integer orderid);}
